package com.doit.day01

import scala.io.Source


case class ScalaHero(id:Int,name:String,age:Int,power:Int)

class MyScalaIterator extends Iterator[ScalaHero]{

  private val lines: Iterator[String] = Source.fromFile("D:\\develop\\ideaWorkSpace\\myself\\Teach\\scalaDemo\\data\\hero").getLines()


  override def hasNext: Boolean = lines.hasNext

  override def next(): ScalaHero = {
    //获取到了这一行数据
    val line: String = lines.next()
    //处理数据的逻辑
    //1_寒冰射手:18,100
    val arr: Array[String] = line.split("_")
    val arr2: Array[String] = arr(1).split(":")
    val arr3: Array[String] = arr2(1).split(",")

    new ScalaHero(arr(0).toInt,arr2(0),arr3(0).toInt,arr3(1).toInt)
  }
}

object ScalaTest{
  def main(args: Array[String]): Unit = {
    val iterator: MyScalaIterator = new MyScalaIterator()
    while(iterator.hasNext){
      println(iterator.next())
    }
  }
}
